package cn.shop.dys.util;

/**
 * Created by ZhJun on 2016/4/20.
 */
public class TimeUtil {
    private int hourStr;

    /**
     * 将xxxx 秒转成 xx：xx:xx; 小时：分钟：秒
     *
     * @param time
     * @return
     */
    public static String secToTime(int time) {
        String timeStr = null;
        int hour = 0;
        int minute = 0;
        int second = 0;
        if (time <= 0)
            return "00:00";
        else {
            minute = time / 60;
            if (minute < 60) {
                second = time % 60;
                timeStr = unitFormat(minute) + ":" + unitFormat(second);
            } else {
                hour = minute / 60;
                if (hour > 99)
                    return "99:59:59";
                minute = minute % 60;
                second = time - hour * 3600 - minute * 60;
                timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":" + unitFormat(second);
            }
        }
        return timeStr;
    }

    public static String unitFormat(int i) {
        String retStr = null;
        if (i >= 0 && i < 10)
            retStr = "0" + Integer.toString(i);
        else
            retStr = "" + i;
        return retStr;
    }

    /**
     *将毫秒时间转成xxx天xxx小时xxx分xxx秒
     * @param time
     * @return
     */
    public static String getTimeFromInt(long time) {
        if (time <= 0) { return "已结束"; }
        long day = time / (1 * 60 * 60 * 24);
        long hour = time / (1 * 60 * 60) % 24;
        long minute = time / (1 * 60) % 60;
        long second = time / (1) % 60;
        return "还剩：" + day + "天" + hour + "小时" + minute + "分" + second + "秒";
    }
}
